//
//  MyDefine.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/8/20.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import Foundation
import UIKit
import SDWebImage

//html图片链接前缀
var kmUrl = "http://m.kameng98.com"
//网页链接前缀
var kmHttps = "https://m.kameng98.com"

let mapKey = "918ef516e0380b673a9be351c58111ff" //高德地图key

/// 状态栏高度
var StatusBarHeight : CGFloat {
    return UIApplication.shared.statusBarFrame.size.height
}

/// 导航栏高度
var NAVBarHeight : CGFloat {
    return UINavigationController().navigationBar.bounds.size.height
}

/// 状态栏高度 + 导航栏高度
var StatusBarAddNavBarHeight : CGFloat {
    return StatusBarHeight + NAVBarHeight
}



/// 屏幕宽度
var ScreenW : CGFloat {
    return UIScreen.main.bounds.size.width
}

/// 屏幕高度
var ScreenH : CGFloat {
    return UIScreen.main.bounds.size.height
}

/// iPhoneX
var isIPhoneX : Bool {
    
    return ScreenW == 375 && ScreenH == 812
}

func RATIO(_ num:CGFloat) -> CGFloat {
    return num * ((UIScreen.main.bounds.size.width) / 375.0)
}

func RATIO_H(_ num:CGFloat) -> CGFloat {
    return num * ((UIScreen.main.bounds.size.height) / 667.0)
}

func RATIO(maxNum:CGFloat) -> CGFloat {
    let a = maxNum * ((UIScreen.main.bounds.size.width) / 375.0)
    return a > maxNum ? maxNum : a
}

func RATIO_H(maxNum:CGFloat) -> CGFloat {
    let a = maxNum * ((UIScreen.main.bounds.size.height) / 667.0)
    return a > maxNum ? maxNum : a
}

// // MARK: - 清理图片内存缓存
func ClearMemoryCache() {
    SDImageCache.shared().clearMemory()
}

// MARK: - 验证正则表达式
/// 验证正则表达式
///
/// - Parameters:
///   - info: 文本
///   - regex: 正则
/// - Returns: 是否匹配正则
public func ValidateInfo(_ info:String? , regex:String) -> Bool {
    
    let textTest:NSPredicate = NSPredicate.init(format:  "SELF MATCHES %@", regex)
    return textTest.evaluate(with: info)
}

// MARK: - 打印方法
func MyLog<T>(_ message : T,file:String = #file,methodName: String = #function, lineNumber: Int = #line){
    #if DEBUG
    let fileName = (file as NSString).lastPathComponent
    let dateForm = DateFormatter.init()
    dateForm.dateFormat = "HH:mm:ss:SSS"
    print("[\(fileName)][\(lineNumber)][\(dateForm.string(from: Date()))]\(methodName):\(message)")
    #endif
    
}

// MARK: - rgba值
func RGBA(r:CGFloat,g:CGFloat,b:CGFloat,a:CGFloat) -> UIColor {
    return UIColor.init(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
